﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoPro.Local;
using CoPro.Configuration;
using CoPro.Provisioning;
using CoPro.Provisioning.ContentProvider;

namespace CoPro
{
    internal class CoProManager
    {
        //Singleton Logic
        private static CoProManager instance;


        public static CoProManager Current
        {
            get
            {
                if (instance == null)
                {
                    instance = new CoProManager();
                }

                return instance;
            }
        }



        //Application Logic

        internal IContentLocal DefaultLocal
        {
            get
            {
                return new ContentLocal("en", true);
            }
        }

        private ContentProviderMap ContentProviderMap;

        internal ILocalProvider LocalProvider { get; set; }

        private CoProManager()
        {
            LoadFromConfig();
            //TODO Get from config
            LocalProvider = new ThreadLocalProvider();
        }

        public IContentProvider GetProvider(String _providerName)
        {
            return ContentProviderMap[_providerName]; 
        }

        private void LoadFromConfig()
        {
            CoProConfig config = CoProConfig.GetConfig();

            LoadProviders(config);
        }

        private void LoadProviders(CoProConfig config)
        {
            ContentProviderMap = new ContentProviderMap(config.Providers, config.DefaultProvider);
        }

    }
}
